import MarkdownIt from "markdown-it";
export function fetchData(options) {
  return new Promise((resolve, reject) => {
    uni.request({
      ...options,
      url: `http://localhost:3000${options.url}`,
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(new Error("请求失败"));
        }
      },
      fail: (error) => {
        console.log(error);
        reject(error);
      },
    });
  });
}
export function selectFromQuery(query, selector, action) {
  return new Promise((resolve) => {
    query.select(selector)[action](resolve).exec();
  });
}
export const md = new MarkdownIt();
export const STUDY_HISTORY = "STUDY_HISTORY";
export function formatTime(time) {
  const date = new Date(time);
  return `${date.getFullYear()}年${
    date.getMonth() + 1
  }月${date.getDate()}日${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
}
